package com.cheer.controller;

import com.cheer.common.Page;
import com.cheer.common.Result;
import com.cheer.dto.MallComplaintQueryDTO;
import com.cheer.dto.MallComplaintReplyDTO;
import com.cheer.service.MallComplaintService;
import com.cheer.vo.MallComplaintListVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author cheer
 */
@RestController
@RequestMapping("/complaint")
public class MallComplaintController {

    @Autowired
    private MallComplaintService mallComplaintService;

    @ApiOperation("查询投诉分页列表")
    @PostMapping("/list")
    @PreAuthorize("@permissionValidator.isAdmin()")
    public Result<Page<MallComplaintListVO>> list(@RequestBody MallComplaintQueryDTO complaintQueryDTO) {
        return Result.success(mallComplaintService.listByQueryCondition(complaintQueryDTO));
    }

    @ApiOperation("答复投诉")
    @PostMapping("/reply")
    @PreAuthorize("@permissionValidator.isAdmin()")
    public Result reply(@RequestBody @Valid MallComplaintReplyDTO complaintReplyDTO) {
        mallComplaintService.reply(complaintReplyDTO);
        return Result.success();
    }

    @ApiOperation("删除投诉")
    @PostMapping("/delete")
    @PreAuthorize("@permissionValidator.isAdmin()")
    public Result delete(@RequestBody List<Long> ids) {
        mallComplaintService.delete(ids);
        return Result.success();
    }
}
